function clone (obj) {
    return JSON.parse(JSON.stringify(obj))
}
//时间操作相关函数
function formatDate (time,opreate='.') {
    var temp = new Date(time);
    temp = `${temp.getFullYear()}${opreate}${(temp.getMonth() + 1).toString().padStart(2,'0')}${opreate}${(temp.getDate()).toString().padStart(2,'0')}`;
    return temp;
}
function formatFullDate(time,opreate='.'){
    var temp = new Date(time);
    temp = `${temp.getFullYear()}${opreate}${(temp.getMonth() + 1).toString().padStart(2,'0')}${opreate}${(temp.getDate()).toString().padStart(2,'0')} ${(temp.getHours()).toString().padStart(2,'0')} : ${(temp.getMinutes()).toString().padStart(2,'0')} : ${(temp.getSeconds()).toString().padStart(2,'0')}`;
    return temp;
}
function getNowDayZero () {
    var time = new Date();
    return new Date(`${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}  0:0:0`);
}
function getNowMonthZero () {
    var time = new Date();
    return new Date(`${time.getFullYear()}-${time.getMonth() + 1}-1  0:0:0`);
}
function getBeforeYears(n,options){
    var time = new Date();
    if(options === 'zero'){
        return new Date(`${time.getFullYear() - n}-${time.getMonth() + 1}-${time.getDate()}  0:0:0`);
    } else if(options === 'integer'){
        return new Date(`${time.getFullYear() - n}-1-1 0:0:0`);
    } else{
        return new Date(`${time.getFullYear() - n}-${time.getMonth() + 1}-${time.getDate()} ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);
    }

}
function getBeforeMonths(n,options){
    var time = new Date();
    var year = time.getFullYear();
    var month = time.getMonth() + 1;
    while(n--){
        if(month === 1){
            month = 12;
            year--;
        }else{
            month--;
        }
    }
    if(options === 'zero'){
        return new Date(`${year}-${month}-${time.getDate()} 0:0:0`);
    } else if(options === 'integer'){
        return new Date(`${year}-${month}-1 0:0:0`);
    } else{
        return new Date(`${year}-${month}-${time.getDate()} ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);
    }
}
function getBeforeDates(n,options){
    var time = new Date();
    if(options === 'zero'){
        return new Date(Date.parse(`${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}  0:0:0`) - 24 * 60 * 60 * 1000 *n);
    }else{
        return new Date(time.getTime() - 24 * 60 * 60 * 1000 * n);
    }
}
function getAfterMonths(n,options){
    var time = new Date();
    var year = time.getFullYear();
    var month = time.getMonth() + 1;
    while(n--){
        if(month === 12){
            month = 1;
            year++;
        }else{
            month++;
        }
    }
    if(options === 'zero'){
        return new Date(`${year}-${month}-${time.getDate()} 0:0:0`);
    } else if(options === 'integer'){
        return new Date(`${year}-${month}-1 0:0:0`);
    } else{
        return new Date(`${year}-${month}-${time.getDate()} ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);
    }
}
export default {
    clone,
    formatDate,
    formatFullDate,
    getNowDayZero,
    getNowMonthZero,
    getBeforeYears,
    getBeforeMonths,
    getBeforeDates,
    getAfterMonths,
}
